package com.prj.ufdm.cloud.ms.auth.bpo._impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.prj.ufdm.cloud.base.util.BaseUuidUtil;
import com.prj.ufdm.cloud.ms.auth.bpo.SysUserDutyBPO;
import com.prj.ufdm.cloud.ms.auth.dao.SysUserDutyDao;
import com.prj.ufdm.cloud.ms.auth.model.SysUserDuty;
import com.prj.ufdm.cloud.ms.core.bpo._impl.BaseBPOImpl;

/**
 * DESC: 用户职务服务实现类 <br>
 * @author 胡义振
 * @date 2020年1月14日
 */
@Service 
public class SysUserDutyBPOImpl extends BaseBPOImpl<SysUserDutyDao,SysUserDuty> implements SysUserDutyBPO{
	
    @Autowired
    private SysUserDutyDao sysUserDutyDao;
    
	/**
	 * DESC: 为用户添加职务
	 * @auther 胡义振
	 * @date 2020年1月16日
	 * @param userId
	 * @param dutyIds
	 * @throws Exception 
	 * @return
	 */
	@Override
	public void doAddUserDuty(String userId,String dutyIds) throws Exception {
		String[] arrDutyId = dutyIds.split(",");
		List<SysUserDuty> listSysUserDuty = new ArrayList<SysUserDuty>();
		for(String dutyId : arrDutyId){
			SysUserDuty sysUserDuty = new SysUserDuty();
			sysUserDuty.setId(BaseUuidUtil.getUUID());
			sysUserDuty.setUserId(userId);
			sysUserDuty.setDutyId(dutyId);
			sysUserDutyDao.deleteUserDutyByUserIdAndDutyId(sysUserDuty);
			listSysUserDuty.add(sysUserDuty);
		}
		sysUserDutyDao.insertBatch(listSysUserDuty);
	}
	
	/**
	 * DESC: 职务添加用户
	 * @auther 胡义振
	 * @date 2020年1月16日
	 * @param dutyId
	 * @param userIds
	 * @throws Exception 
	 * @return
	 */
	@Override
	public void doAddDutyUser(String dutyId,String userIds) throws Exception {
		String[] arrUserId = userIds.split(",");
		List<SysUserDuty> listSysUserDuty = new ArrayList<SysUserDuty>();
		for(String userId : arrUserId){
			SysUserDuty sysUserDuty = new SysUserDuty();
			sysUserDuty.setId(BaseUuidUtil.getUUID());
			sysUserDuty.setUserId(userId);
			sysUserDuty.setDutyId(dutyId);
			sysUserDutyDao.deleteUserDutyByUserIdAndDutyId(sysUserDuty);
			listSysUserDuty.add(sysUserDuty);
		}
		sysUserDutyDao.insertBatch(listSysUserDuty);
	}

	/**
	 * DESC: 删除用户职务对应关系
	 * @auther 胡义振
	 * @date 2020年1月16日
	 * @param userId
	 * @param dutyId
	 * @throws Exception 
	 * @return
	 */
	@Override
	public void doDelUserDuty(String userId,String dutyId) throws Exception {
		SysUserDuty sysUserDuty = new SysUserDuty();
		sysUserDuty.setUserId(userId);
		sysUserDuty.setDutyId(dutyId);
		sysUserDutyDao.deleteUserDutyByUserIdAndDutyId(sysUserDuty);
		
	}


}
